Skip to content

Conversation

@majdyz
Copy link
Contributor

@majdyz majdyz commented Nov 26, 2025

Summary

This PR implements a graph-level Safe Mode toggle system for Human-in-the-Loop (HITL) blocks. When Safe Mode is ON (default), HITL blocks require manual review before proceeding. When OFF, they execute automatically.

🔧 Backend Changes

  • Database: Added metadata JSON column to AgentGraph table with migration
  • API: Updated execute_graph endpoint to accept safe_mode parameter
  • Execution: Enhanced execution context to use graph metadata as default with API override capability
  • Auto-detection: Automatically populate has_human_in_the_loop for graphs containing HITL blocks
  • Block Detection: HITL block ID: 8b2a7b3c-6e9d-4a5f-8c1b-2e3f4a5b6c7d

🎨 Frontend Changes

  • Component: New FloatingSafeModeToggle with dual variants:
    • White variant: For library pages, integrates with action buttons
    • Black variant: For builders, floating positioned
  • Integration: Added toggles to both new/legacy builders and library pages
  • API Integration: Direct graph metadata updates via usePutV1UpdateGraphVersion
  • Query Management: React Query cache invalidation for consistent UI updates
  • Conditional Display: Toggle only appears when graph contains HITL blocks

🛠 Technical Implementation

  • Safe Mode ON (default): HITL blocks require manual review before proceeding
  • Safe Mode OFF: HITL blocks execute automatically without intervention
  • Priority: Backend API safe_mode parameter takes precedence over graph metadata
  • Detection: Auto-populates has_human_in_the_loop metadata field
  • Positioning: Proper z-index and responsive positioning for floating elements

🚧 Known Issues (Work in Progress)

High Priority

  • Toggle state persistence: Always shows "ON" regardless of actual state - query invalidation issue
  • LibraryAgent metadata: Missing metadata field causing TypeScript errors
  • Tooltip z-index: Still covered by some UI elements despite high z-index

Medium Priority

  • HITL detection: Logic needs improvement for reliable block detection
  • Error handling: Removing HITL blocks from graph causes save errors
  • TypeScript: Fix type mismatches between GraphModel and LibraryAgent

Low Priority

  • Frontend API: Add safe_mode parameter to execution calls once OpenAPI is regenerated
  • Performance: Consider debouncing rapid toggle clicks

🧪 Test Plan

  • Verify toggle appears only when graph has HITL blocks
  • Test toggle persistence across page refreshes
  • Confirm API calls update graph metadata correctly
  • Validate execution behavior respects safe mode setting
  • Check styling consistency across builder and library contexts

🔗 Related

  • Addresses requirements for graph-level HITL configuration
  • Builds on existing FloatingReviewsPanel infrastructure
  • Integrates with existing graph metadata system

🤖 Generated with Claude Code

@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/human-in-the-loop-block-toggle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AutoGPT-Agent
Copy link

Thank you for this comprehensive PR implementing a graph-level Safe Mode toggle for HITL blocks. The code changes look solid, and your PR description does an excellent job of explaining the intent and implementation details.

However, I noticed that you haven't checked off any of the items in your test plan. Before this can be merged, please:

  1. Complete the testing of your implementation according to the test plan you've outlined
  2. Check off the test plan items in your PR description once they've been verified

This feature affects execution behavior for HITL blocks, so thorough testing is particularly important to ensure it works as expected across different contexts (builder and library pages).

Also, I noted a few of your known issues:

  • Toggle state persistence showing "ON" regardless of actual state
  • LibraryAgent metadata TypeScript errors
  • Z-index issues with tooltip

While these don't necessarily block merging, it would be good to know if you have plans to address them in this PR or follow-up PRs.

Let me know if you need any clarification or have questions about these requirements.

@deepsource-io
Copy link

deepsource-io bot commented Nov 26, 2025

Here's the code health analysis summary for commits a37b527..e06725b. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript✅ Success
❗ 35 occurences introduced
🎯 22 occurences resolved
View Check ↗
DeepSource Python LogoPython✅ Success
❗ 63 occurences introduced
🎯 50 occurences resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@AutoGPT-Agent
Copy link

Thanks for the comprehensive PR implementing the Safe Mode toggle for HITL blocks! The implementation looks thorough and well-thought-out. I have a few comments before this is ready to merge:

Test Plan Completion

The test plan is clearly specified in your PR description, but none of the items are checked off. Could you please complete the testing as outlined and check off the test plan items? Specifically:

  • Verify toggle appears only when graph has HITL blocks
  • Test toggle persistence across page refreshes
  • Confirm API calls update graph metadata correctly
  • Validate execution behavior respects safe mode setting
  • Check styling consistency across builder and library contexts

Known Issues

You've done a great job documenting the known issues. Since these are marked as "Work in Progress", could you clarify which of these need to be resolved before merging versus which can be addressed in follow-up PRs?

Particularly concerning are these high priority issues:

  • Toggle state persistence always showing "ON"
  • TypeScript errors with LibraryAgent metadata
  • Z-index issues with tooltips

Technical Questions

  1. The HITL block ID is hardcoded (8b2a7b3c-6e9d-4a5f-8c1b-2e3f4a5b6c7d). Is there a more robust way to detect HITL blocks that won't break if block IDs change?
  2. Could you add some comments around the API priority logic where safe_mode parameter takes precedence over graph metadata?

Migration Readiness

The migration looks good, but let's ensure it's been tested on a representative database. Have you verified the migration runs successfully on a database with existing graphs?

Overall, this is a well-implemented feature with good cross-cutting concerns addressed. Looking forward to getting the test plan completed!

@majdyz majdyz force-pushed the feat/human-in-the-loop-block-toggle branch from 121ceb6 to 4e686d7 Compare November 26, 2025 11:52
@AutoGPT-Agent
Copy link

Thank you for this detailed PR implementing the graph-level Safe Mode toggle for HITL blocks!

Feedback

Your implementation looks comprehensive, covering both backend and frontend changes needed for this feature. I appreciate the detailed description with sections for backend changes, frontend changes, technical implementation, and known issues.

A few observations:

  1. Missing Standard Checklist: Could you please add our standard checklist for code changes? Since this is a substantial feature implementation (labeled as size/xl), we need to ensure all verification steps are covered.

  2. Execution Context: The change from UserContext to ExecutionContext seems well implemented throughout the codebase, ensuring all references are updated consistently.

  3. Known Issues: It's good that you've documented the known issues, particularly around toggle state persistence, but these would need to be addressed before merging or at least have clear follow-up tasks created.

  4. Test Plan: Your test plan is helpful, but when you add the standard checklist, please ensure you've included specific verification steps for this feature.

  5. User ID Validation: The changes to backend/data/graph.py correctly validate user access in the update_graph_metadata function, which is good.

Once you've added the standard PR checklist with your test plan and addressed the known issues (or planned follow-ups), this should be ready for review again.

@AutoGPT-Agent
Copy link

Thank you for this PR implementing a graph-level Safe Mode toggle for HITL blocks. The feature looks well-designed and adds important safety functionality to the platform.

However, there's one key issue that needs to be addressed before this PR can be merged:

Required Changes

  • Missing PR Checklist: Our PR template requires a completed checklist for all PRs with material code changes. Please add the standard PR checklist from the template and ensure all items are checked off or explained.

Additional Feedback

  • The implementation generally looks solid. I especially like the detailed technical implementation and known issues sections in your description.
  • The backend changes for the Safe Mode feature appear to be implemented correctly, with proper database migrations and API updates.
  • The frontend components for the toggle are well-designed with appropriate variants for different contexts.
  • Good job on considering the UX implications of the toggle placement in different views.

Once you add the required checklist, this PR should be ready for review and potential approval.

@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Nov 26, 2025
@github-actions
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

Base automatically changed from feat/human-in-the-loop-block to dev November 27, 2025 05:07
@majdyz majdyz force-pushed the feat/human-in-the-loop-block-toggle branch from 1a15c4a to a8e4de3 Compare November 28, 2025 04:09
@netlify
Copy link

netlify bot commented Nov 28, 2025

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
🔨 Latest commit e06725b
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs-dev/deploys/6929cd70e4494d0008975eb0

@github-actions
Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Nov 28, 2025
@netlify
Copy link

netlify bot commented Nov 28, 2025

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit e06725b
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs/deploys/6929cd705a3770000899c0d6

@AutoGPT-Agent
Copy link

Thank you for submitting this comprehensive PR implementing the graph-level Safe Mode toggle for HITL blocks! The changes look well-structured with both backend and frontend components properly addressed.

However, before we can merge this PR, please address the following issues:

Missing Checklist

  • Please add the standard PR checklist to your description and check off all the relevant items
  • Ensure you've completed a proper test plan as you mentioned in your description

Technical Feedback

  • You've identified several known issues in your description. Are any of these blocking for this PR, or are they intended to be addressed in follow-up PRs?
  • The toggle state persistence issue mentioned in your known issues seems significant - can you provide more context on how this affects functionality?

Once you've addressed these points, particularly completing the checklist, this PR should be ready for review and merging. The implementation itself looks solid, with proper database migrations, user_id handling, and appropriate type definitions.

@majdyz majdyz force-pushed the feat/human-in-the-loop-block-toggle branch from 44a16c1 to 98c1377 Compare November 28, 2025 07:21
@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Nov 28, 2025
@github-actions
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@majdyz majdyz force-pushed the feat/human-in-the-loop-block-toggle branch from b555336 to 2d4595f Compare November 28, 2025 15:51
@github-actions
Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Nov 28, 2025
@majdyz majdyz marked this pull request as ready for review November 28, 2025 15:52
@majdyz majdyz requested a review from a team as a code owner November 28, 2025 15:52
@majdyz majdyz requested review from Swiftyos and kcze and removed request for a team November 28, 2025 15:52
@AutoGPT-Agent
Copy link

Thank you for this comprehensive PR implementing the graph-level Safe Mode toggle for HITL blocks. The changes look well-structured with a clear separation between backend and frontend components.

Before this PR can be merged, please add the required checklist to your PR description. Since this is a substantial code change (labeled as size/xl), we need the checklist to ensure all necessary testing and verification has been completed.

A few additional suggestions:

  1. Some of your "Known Issues" are marked as high priority. Consider addressing at least the high-priority ones before merging, particularly the "Toggle state persistence" issue which could lead to unexpected behavior.

  2. The PR has a conflicts label - please resolve these merge conflicts.

  3. Consider adding explicit type checking for the new GraphSettings model to ensure type safety.

The implementation itself looks solid - I particularly like how you've:

  • Added automatic detection of HITL blocks in graphs
  • Made safe mode the default (security-first approach)
  • Provided override capability via the API
  • Added database migrations for the new settings column

Once you've added the checklist and addressed any merge conflicts, this PR should be ready for another review.

@AutoGPT-Agent
Copy link

Thanks for this comprehensive PR implementing the graph-level Safe Mode toggle for HITL blocks. The feature seems well-designed, covering both backend and frontend aspects.

Good Implementation Points

  • Comprehensive approach with database migration, execution context enhancement, and frontend components
  • Good separation of concerns between backend execution logic and frontend toggle UI
  • Proper detection of graphs containing HITL blocks
  • Thoughtful default settings (safe mode ON by default)
  • Re-use of existing infrastructure (FloatingReviewsPanel pattern)

Areas Needing Attention

  1. Incomplete Test Plan: Your test plan checklist items are not checked off, which is required before merging. Please complete the testing and update the checklist.

  2. Known Issues: You've listed several high-priority issues in your description:

    • Toggle state persistence issues
    • LibraryAgent metadata TypeScript errors
    • Z-index problems with tooltips

    These high-priority issues should be resolved before the PR is ready for merge, or at least have a clear path to resolution.

  3. OpenAPI Generation: You mentioned needing to add the safe_mode parameter to execution calls after OpenAPI regeneration. This should be completed before merging.

Once you've completed the test plan and addressed the high-priority issues, this PR will be ready for another review. The core implementation looks solid!

return GraphSettings.model_validate(lib.settings)
except Exception:
logger.warning(
f"Malformed settings for LibraryAgent user={user_id} graph={graph_id}"

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.

Copilot Autofix

AI about 1 hour ago

The best fix is to remove or redact sensitive user-specific information from log messages. In the specific case of autogpt_platform/backend/backend/data/graph.py, at line 1138, the warning logs both user_id and graph_id in cleartext. Rather than logging these values directly, we should instead use a generic message, e.g. "Malformed settings for LibraryAgent" without referencing specific IDs, or redact them (e.g. logging only a shortened prefix, or hashing them, or using a placeholder).

Recommended fix for the affected region:

  • Change the logger.warning call at line 1138 so that user_id and graph_id are not logged in their entirety.
  • If operational value is needed, log only that a problem occurred, omitting IDs; if necessary for debugging, include only partial/hashing, or instruct to query with context outside logs.
  • This is a one-line change inside the function get_graph_settings in autogpt_platform/backend/backend/data/graph.py.

No additional imports or functions/methods are needed.


Suggested changeset 1
autogpt_platform/backend/backend/data/graph.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.py
--- a/autogpt_platform/backend/backend/data/graph.py
+++ b/autogpt_platform/backend/backend/data/graph.py
@@ -1135,7 +1135,7 @@
         return GraphSettings.model_validate(lib.settings)
     except Exception:
         logger.warning(
-            f"Malformed settings for LibraryAgent user={user_id} graph={graph_id}"
+            "Malformed settings for LibraryAgent (redacted identifiers)"
         )
         return GraphSettings()
 
EOF
@@ -1135,7 +1135,7 @@
return GraphSettings.model_validate(lib.settings)
except Exception:
logger.warning(
f"Malformed settings for LibraryAgent user={user_id} graph={graph_id}"
"Malformed settings for LibraryAgent (redacted identifiers)"
)
return GraphSettings()

Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines 391 to 401
if not user:
raise HTTPException(status_code=404, detail="User not found.")

user_context = UserContext(timezone=user.timezone)

start_time = time.time()
try:
output = defaultdict(list)
async for name, data in obj.execute(
data,
user_context=user_context,
user_id=user_id,
# Note: graph_exec_id and graph_id are not available for direct block execution
):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing execution_context in execute_graph_block() for HITL blocks.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The execute_graph_block() endpoint in v1.py calls obj.execute() without providing the execution_context parameter. The HumanInTheLoop block's run() method, which is eventually called, requires execution_context as a keyword-only argument. This omission will cause a TypeError: missing 1 required positional argument: 'execution_context' when a HITL block is executed directly via this endpoint. This is a regression as user_context (the predecessor to execution_context) was previously passed.

💡 Suggested Fix

Ensure execution_context is properly initialized and passed to obj.execute() within the execute_graph_block endpoint, similar to how user_context was handled previously.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: autogpt_platform/backend/backend/server/routers/v1.py#L387-L401

Potential issue: The `execute_graph_block()` endpoint in `v1.py` calls `obj.execute()`
without providing the `execution_context` parameter. The `HumanInTheLoop` block's
`run()` method, which is eventually called, requires `execution_context` as a
keyword-only argument. This omission will cause a `TypeError: missing 1 required
positional argument: 'execution_context'` when a `HITL` block is executed directly via
this endpoint. This is a regression as `user_context` (the predecessor to
`execution_context`) was previously passed.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4284451

Comment on lines 1577 to 1587
)
if parent_exec and parent_exec.status == ExecutionStatus.TERMINATED:
logger.info(
f"[{self.service_name}] Skipping execution {graph_exec_id} - parent {parent_graph_exec_id} is TERMINATED"
)
# Mark this child as terminated since parent was stopped
get_db_client().update_graph_execution_stats(
graph_exec_id=graph_exec_id,
status=ExecutionStatus.TERMINATED,
)
_ack_message(reject=False, requeue=False)
return
except Exception as e:
logger.warning(
f"[{self.service_name}] Could not check parent status for {graph_exec_id}: {e}"
# Mark this child as terminated since parent was stopped
get_db_client().update_graph_execution_stats(
graph_exec_id=graph_exec_id,
status=ExecutionStatus.TERMINATED,
)
# Continue execution if parent check fails (don't block on errors)
_ack_message(reject=False, requeue=False)
return

# Check user rate limit before processing
try:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unhandled database exception in _handle_run_message.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The _handle_run_message function in manager.py removes a try-except block around the get_db_client().get_graph_execution_meta() call. If this database operation fails (e.g., due to a database connection error or timeout), the unhandled exception will propagate, causing the message handler to crash and potentially terminating the entire consumer thread. The _handle_run_message method is not decorated with @error_logged, so exceptions are not gracefully handled.

💡 Suggested Fix

Re-introduce robust error handling, such as a try-except block, around the get_db_client().get_graph_execution_meta() call within _handle_run_message to prevent crashes from database failures.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: autogpt_platform/backend/backend/executor/manager.py#L1556-L1587

Potential issue: The `_handle_run_message` function in `manager.py` removes a
`try-except` block around the `get_db_client().get_graph_execution_meta()` call. If this
database operation fails (e.g., due to a database connection error or timeout), the
unhandled exception will propagate, causing the message handler to crash and potentially
terminating the entire consumer thread. The `_handle_run_message` method is not
decorated with `@error_logged`, so exceptions are not gracefully handled.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4284451

@majdyz majdyz requested review from 0ubbe and ntindle November 28, 2025 16:06
@AutoGPT-Agent
Copy link

Thank you for this comprehensive PR implementing the graph-level Safe Mode toggle for HITL blocks. The implementation looks solid overall!

Missing Requirements

  • You need to include the checklist from the PR template and mark off the items. Since this is a substantial code change (not just a typo fix), the checklist is required.

Implementation

The technical implementation looks strong with good separation of concerns:

  • The database migration to add settings JSON column to LibraryAgent table
  • The ExecutionContext model that centralizes execution parameters including safe_mode
  • The automatic detection of graphs containing HITL blocks
  • The HITL block enhancement to conditionally skip review when safe mode is disabled

Good job addressing the needs across backend, frontend and blocks!

Known Issues

You've done a good job documenting the known issues. Once the checklist is completed, make sure your test plan verifies that these issues don't critically impact functionality.

Next Steps

  1. Add the completed PR checklist from the template
  2. Make sure you've tested according to your test plan

Once you've addressed these points, the PR should be ready for review again.

@AutoGPT-Agent
Copy link

Thank you for this comprehensive PR! The implementation of a graph-level Safe Mode toggle for HITL blocks looks well-structured and follows good practices. A few observations and suggestions:

  1. Test Plan: Your test plan is well defined but all items are unchecked. Please complete testing and check these items off before the PR is ready for final review.

  2. Code Organization: The way you've structured the execution context changes is clean - moving from UserContext to a more comprehensive ExecutionContext makes the code more maintainable.

  3. High Priority Issues: The known issues you've listed as high priority should ideally be addressed before merging:

    • Toggle state persistence issue
    • LibraryAgent metadata TypeScript errors
    • Tooltip z-index problems
  4. Type Safety: The GraphSettings model and its integration with LibraryAgent is well done. You might want to consider adding stronger type checking for the default values to prevent potential issues.

  5. HITL Block Detection: The caching of HITL block IDs is a good optimization for performance, but as you noted in the known issues, the detection logic might need improvement. Consider adding a test specifically for this functionality.

  6. Documentation: While the code changes are well-commented, consider adding some documentation for other developers about how the safe mode system works and how to properly implement HITL blocks that respect this setting.

Overall this is a well-structured feature implementation. Please address the unchecked test plan items and high priority known issues before merging.

@AutoGPT-Agent
Copy link

Thanks for this detailed PR implementing the graph-level Safe Mode toggle for HITL blocks. The implementation looks solid across backend, frontend, and blocks components.

Missing Checklist

You've provided a thorough description of the changes and even included a test plan section, but the PR is missing the required checklist from the template. Please add the standard checklist section and check off the relevant items.

Code Review Comments

  1. Your implementation of the Safe Mode toggle functionality looks good - it adds the settings to LibraryAgent model with proper DB migration and API endpoints.

  2. The execution context change is a nice improvement over the previous user_context approach, making it more extensible for future options beyond timezone.

  3. Good job on handling backwards compatibility with existing graphs and auto-detecting HITL blocks.

  4. You've included appropriate test updates for the code changes.

  5. The known issues section in your description is helpful for reviewers to understand what's still pending - make sure to address the high priority items before considering this ready for production.

Please update your PR to include the required checklist, and consider addressing the high-priority known issues you've identified before final approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/backend AutoGPT Platform - Back end platform/blocks platform/frontend AutoGPT Platform - Front end size/xl

Projects

Status: 🆕 Needs initial review
Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants